package db

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
)

const (
	userName  string = "root"
	password  string = "19861213hkf"
	ipAddrees string = "localhost"
	port      int    = 3306
	dbName    string = "stu"
	charset   string = "utf8"
)

func Open() *sql.DB {
	// root:19861213hkf@tcp(127.0.0.1:3306)/stu?charset=utf8
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s", userName,password,ipAddrees,port,dbName,charset)
	db, err := sql.Open("mysql", dsn)
	if err != nil {
		fmt.Printf("mysql connect failed, detail is [%v]", err.Error())
	}
	return db
}
